package cn.nawang.ebeim.client.transfer;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by GanJc on 2016-01-04 08:56
 */
public class TransferAuthService {

    private static final Logger LOG = LoggerFactory.getLogger(TransferAuthService.class);

    /**
     * 随机生成的用于存档的字符映射表
     * (存于数据库或文件,重置后,需同时更新服务端和客户端)
     */
    private static String SECRET_DIC = "{\"!\":\"9AWh\",\"#\":\"7m5C\",\"&\":\"dD1&\",\"-\":\"3feL\",\".\":\".ZYE\",\"0\":\"2zdt\",\"1\":\"Ntsw\",\"2\":\"ivMM\",\"3\":\"Dd&K\",\"4\":\".d8a\",\"5\":\"scTG\",\"6\":\"w?OT\",\"7\":\"VeiQ\",\"8\":\".GaM\",\"9\":\"1MEi\",\"=\":\"FSvZ\",\"?\":\"CrSv\",\"@\":\"w2so\",\"A\":\"JpW_\",\"B\":\"-hR?\",\"C\":\"yKE1\",\"D\":\"9.hz\",\"E\":\"?6L9\",\"F\":\"!#RC\",\"G\":\"HJru\",\"H\":\"mzxN\",\"I\":\"wCaj\",\"J\":\"pAMw\",\"K\":\"8@Gd\",\"L\":\"laDF\",\"M\":\"?g5j\",\"N\":\"HXzt\",\"O\":\"BPTm\",\"P\":\"Zxtm\",\"Q\":\"WmXi\",\"R\":\"SOZn\",\"S\":\"3jYb\",\"T\":\"EidD\",\"U\":\"MNld\",\"V\":\"eLe3\",\"W\":\"0#&s\",\"X\":\"9d??\",\"Y\":\"oSPU\",\"Z\":\"Sbso\",\"_\":\"lCUg\",\"a\":\"DRis\",\"b\":\"u1pw\",\"c\":\"VgDE\",\"d\":\"KW12\",\"e\":\"cuM7\",\"f\":\"9Oit\",\"g\":\"MqEV\",\"h\":\"pPA&\",\"i\":\"S_GF\",\"j\":\"yZTh\",\"k\":\"ZZig\",\"l\":\"URY0\",\"m\":\"kM7P\",\"n\":\"?!qd\",\"o\":\"@nY9\",\"p\":\"J#RM\",\"q\":\"c25H\",\"r\":\"fiey\",\"s\":\"ZO#u\",\"t\":\"Hd=M\",\"u\":\"41PR\",\"v\":\"Uyu=\",\"w\":\"cIP-\",\"x\":\"!ZvP\",\"y\":\"QFSC\",\"z\":\"qnbU\"}";

    /**
     * 用于加解密的字符映射表,SECRET_DIC的map版.
     */
    private static Map SECRET_MAP = new HashMap();

    static {
        SECRET_MAP = JSON.parseObject(SECRET_DIC,Map.class);
        LOG.info("SECRET_DIC：{}", SECRET_DIC);
        LOG.info("SECRET_MAP：{}", SECRET_MAP);
    }

    public static String encryptUrl(String url) {
        String[] strings = url.split("");
        StringBuffer sb = new StringBuffer(strings.length * 4);
        for (String s : strings) {
            sb.append(SECRET_MAP.get(s));
        }
        return sb.toString();
    }

}


